package com.ruoyi.magazine.magazine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.magazine.magazine.domain.Magazine;
import com.ruoyi.magazine.magazine.service.IMagazineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 杂志管理Controller
 * 
 * @author duanxinli
 * @date 2023-11-10
 */
@RestController
@RequestMapping("/magazine/magazine")
public class MagazineController extends BaseController
{
    @Autowired
    private IMagazineService magazineService;

    /**
     * 查询杂志管理列表
     */
//    @PreAuthorize("@ss.hasPermi('magazine:magazine:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Magazine magazine)
    {
        startPage();
        List<Magazine> list = magazineService.selectMagazineList(magazine);
        return getDataTable(list);
    }

    /**
     * 导出杂志管理列表
     */
    @PreAuthorize("@ss.hasPermi('magazine:magazine:export')")
    @Log(title = "杂志管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Magazine magazine)
    {
        List<Magazine> list = magazineService.selectMagazineList(magazine);
        ExcelUtil<Magazine> util = new ExcelUtil<Magazine>(Magazine.class);
        util.exportExcel(response, list, "杂志管理数据");
    }

    /**
     * 获取杂志管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('magazine:magazine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(magazineService.selectMagazineById(id));
    }

    /**
     * 新增杂志管理
     */
    @PreAuthorize("@ss.hasPermi('magazine:magazine:add')")
    @Log(title = "杂志管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Magazine magazine)
    {
        return toAjax(magazineService.insertMagazine(magazine));
    }

    /**
     * 修改杂志管理
     */
    @PreAuthorize("@ss.hasPermi('magazine:magazine:edit')")
    @Log(title = "杂志管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Magazine magazine)
    {
        return toAjax(magazineService.updateMagazine(magazine));
    }

    /**
     * 删除杂志管理
     */
    @PreAuthorize("@ss.hasPermi('magazine:magazine:remove')")
    @Log(title = "杂志管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(magazineService.deleteMagazineByIds(ids));
    }
}
